package com.simpleFactory;

import java.util.Scanner;

public class Calculator {
    public static void main(String[] args) {
        System.out.println("请输入数字A:");
        Scanner scanA = new Scanner(System.in);
        String strNumberA = scanA.nextLine();

        System.out.println("请选择运算符号（+ - * /）:");
        Scanner scanOper = new Scanner(System.in);
        String strOperate = scanOper.nextLine();

        System.out.println("请输入数字B:");
        Scanner scanB = new Scanner(System.in);
        String strNumberB = scanB.nextLine();

        String strResult = "";
        switch (strOperate){
            case "+":
                strOperate = String.valueOf(Double.valueOf(strNumberA)+Double.valueOf(strNumberB));
                break;
            case "-":
                strOperate = String.valueOf(Double.valueOf(strNumberA)-Double.valueOf(strNumberB));
                break;
            case "*":
                strOperate = String.valueOf(Double.valueOf(strNumberA)*Double.valueOf(strNumberB));
                break;
            case "/":
                if (strNumberB != "0"){
                    strOperate = String.valueOf(Double.valueOf(strNumberA)/Double.valueOf(strNumberB));
                }else {
                    strResult = "除数不能为0";
                }
                break;
        }
        System.out.println("结果为："+strResult);
    }
}
